Skip to content

feat: added AndroidNativeAnrEnabled and related options#2671

Merged
bitsandfoxes merged 15 commits into
chore/new-unity-structurefrom
feat/android-anr-v2
May 12, 2026
Merged

feat: added AndroidNativeAnrEnabled and related options#2671
bitsandfoxes merged 15 commits into
chore/new-unity-structurefrom
feat/android-anr-v2

Conversation

@bitsandfoxes
Copy link
Copy Markdown
Contributor

@bitsandfoxes bitsandfoxes commented May 8, 2026

Problem

Unity games can get stuck in multiple places and as of right now the SDK surfaces only the C# watchdog integration to capture ANRs. This comes with several limitations. sentry-java has its own ANR integrations that the SDK currently hardcoded opts-out.

Context

Unity games have their own main thread. The sentry-java SDK has a v1 and a v2 ANR integration that monitors the Android UI thread.

There are these native options:

  • enableAnr
  • enableScopePersistence
  • isReportHistoricalAnrs
  • isAttachAnrThreadDump

Since the work next to each other we keep the umbrella flags AnrDetectionEnabled and AndroidNativeAnrEnabled separated.

The way this works is on API >= 30 sentry-java will use ApplicationExitInfo to read OS-reported ANRs to generate events out of those. Since this happens on the next launch, enableScopePersistence allows the SDK to store the scope to disk to then enrich the event with the scope at the time of the ANR.

Proposal

We can surface these options and pass them to sentry-java. These are especially valuable if users have their own launcher, or plugins running outside of the Unity game loop.
sentry-java takes care of picking the supported ANR integration. On API < 30 this is "just" a watchdog, similar to what we have for C#.

Follow Up

There are a couple of follow-ups:

  1. The sentry-java manifest needs to accept the historic anr capture flag, see feat: added ANR_REPORT_HISTORICAL to the ManifestMetaDataReader sentry-java#5387
  2. Improvements to our C# anr capture mechanism see ANR Detection Improvements #1961
  3. Add ANR capture to e2e tests
  4. Add native ANR trigger to samples

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against dd93d8d

@bitsandfoxes bitsandfoxes requested a review from a team May 11, 2026 07:27
Comment on lines +143 to +144
androidOptions.Call("setAnrEnabled", options.AndroidNativeAnrEnabled);
androidOptions.Call("setEnableScopePersistence", options.AndroidNativeAnrEnabled);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setEnableScopePersistence only affects the ANR v2 and the tombstone integration. And the Unity SDK only surfaces the ANR with this PR. So I'm opting to keep this option merged into the AnrNativeAnrEnabled.

@bitsandfoxes bitsandfoxes merged commit 41c7551 into chore/new-unity-structure May 12, 2026
125 of 127 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/android-anr-v2 branch May 12, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants